package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysWorkLog;
import com.ruoyi.system.service.ISysWorkLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 运行日志Controller
 * 
 * @author ruoyi
 * @date 2023-02-02
 */
@RestController
@RequestMapping("/system/log")
public class SysWorkLogController extends BaseController
{
    @Autowired
    private ISysWorkLogService sysWorkLogService;

    /**
     * 查询运行日志列表
     */
    @PreAuthorize("@ss.hasPermi('system:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysWorkLog sysWorkLog)
    {
        startPage();
        List<SysWorkLog> list = sysWorkLogService.selectSysWorkLogList(sysWorkLog);
        return getDataTable(list);
    }

    /**
     * 导出运行日志列表
     */
    @PreAuthorize("@ss.hasPermi('system:log:export')")
    @Log(title = "运行日志", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysWorkLog sysWorkLog)
    {
        List<SysWorkLog> list = sysWorkLogService.selectSysWorkLogList(sysWorkLog);
        ExcelUtil<SysWorkLog> util = new ExcelUtil<SysWorkLog>(SysWorkLog.class);
        return util.exportExcel(list, "log");
    }

    /**
     * 获取运行日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:log:query')")
    @GetMapping(value = "/{logId}")
    public AjaxResult getInfo(@PathVariable("logId") Long logId)
    {
        return AjaxResult.success(sysWorkLogService.selectSysWorkLogById(logId));
    }

    /**
     * 新增运行日志
     */
    @PreAuthorize("@ss.hasPermi('system:log:add')")
    @Log(title = "运行日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysWorkLog sysWorkLog)
    {
        sysWorkLogService.insertSysWorkLog(sysWorkLog);

        return AjaxResult.success(sysWorkLogService.getNewLogId());
    }

    /**
     * 修改运行日志
     */
    @PreAuthorize("@ss.hasPermi('system:log:edit')")
    @Log(title = "运行日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysWorkLog sysWorkLog)
    {
        return toAjax(sysWorkLogService.updateSysWorkLog(sysWorkLog));
    }

    /**
     * 删除运行日志
     */
    @PreAuthorize("@ss.hasPermi('system:log:remove')")
    @Log(title = "运行日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{logIds}")
    public AjaxResult remove(@PathVariable Long[] logIds)
    {
        return toAjax(sysWorkLogService.deleteSysWorkLogByIds(logIds));
    }
}
